﻿// ***********************************************************************
// Assembly         : OSS.ModelViewer
// Author           : tian_
// Created          : 05-16-2018
//
// Last Modified By : tian_
// Last Modified On : 07-17-2018
// ***********************************************************************
// <copyright file="osgProjectApp.cs" company="">
//     Copyright ©  2018
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Reflection;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraBars.Ribbon;
using OSS.ModelViewer.Commands;
using OSS.ModelViewer.Commands.TestCmds;
using OSS.ModelViewer.Commands.UserTestCmds;
using OSS.ModelViewer.Properties;
using OSS.ModelViewer.Utility;
using ZfPlatform.DevExpressGUI;
using ZFGK.Addins;
using ZFGK.OSG.UI;
using ZFGK.OSG.UI.Commands;
using ZFGK.DevExprss.Utility;
using ZFGK.CommandLine;
using ZFGK.Utility;

namespace OSS.ModelViewer
{
    /// <summary>
    /// Class osgProjectApp.
    /// </summary>
    /// <seealso cref="ZFGK.Addins.IExtendApp" />
    public class ModelViewerApp : IExtendApp
    {
        public static ZfCommandLine commandLine = new ZfCommandLine();
        /// <summary>
        /// Starts up.
        /// </summary>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool StartUp(ExtendAppData data)
        {
            var mainRibbonForm = data.MainForm as MainRibbonForm;
            mainRibbonForm.Text = "智帆智慧模型(ZZModel)";
            mainRibbonForm.Load += delegate(object sender, EventArgs args)
            {
//                 var form = new Form();
//                 form.MdiParent = mainRibbonForm;
//                 form.Text = "Test";
//                 form.Show();
                AddinManager.AddinService.TryRunCmd<OpenOsgViewFormCmd>(mainRibbonForm, null);
            };

            mainRibbonForm.siAbout.Caption = "北京智帆高科科技有限公司 QQ群:621874650";
            InitRibbon(mainRibbonForm.ribbonControl);

            #region 添加浮动窗体
            // 添加停靠窗体
            ZfTreeListManager.TreeList.PopupMenu = mainRibbonForm.popupMenu;
            ZfTreeListManager.TreeList.Dock = DockStyle.Fill;

            var dockPanel1 = DockPanelUtil.New(ZfTreeListManager.TreeList,
                "模型", new Guid("F7841CD0-8B58-4116-8969-F0075B64AF10"), null);
            dockPanel1.Dock = DockingStyle.Left;

            mainRibbonForm.dockManager.RootPanels.AddRange(new[] { dockPanel1 });
            mainRibbonForm.Controls.AddRange(new[] { dockPanel1 });
            #endregion

            OsgDB.Registry.instance().addFileExtensionAlias("stp", "opencascade");
            OsgDB.Registry.instance().addFileExtensionAlias("step", "opencascade");

            ZfTreeListManager.InitTreeViewModel();
            AddinManager.AddinService.RegisterCmd<AddTestCmd>("AddTest");
            return true;
        }

        /// <summary>
        /// Initializes the main form ribbon menu.
        /// </summary>
        /// <param name="ribbonControl">The ribbon control.</param>
        public static void InitRibbon(RibbonControl ribbonControl)
        {
            var addinService = AddinManager.AddinService;
            addinService.RegisterCmd<HighlightCancelCmd>("HighlightCancel");
            // 快捷按钮
            ribbonControl.Toolbar.ItemLinks
                .NewButton("取消高亮", false, btn => btn.Tag = ("HighlightCancel"), btn => btn.SetImage(Resources.cancel, false)
                    , btn => btn.Hint = ("取消所有模型的高亮"));

            addinService.RegisterCmd<OsgFileImportCmd>("OsgFileImport");
            addinService.RegisterCmd<ModelDeleteCmd>("ModelDelete");
            addinService.RegisterCmd<HighlightModelCmd>("HighlightModel");
            addinService.RegisterCmd<ModelSaveAs>("ModelSaveAs");
            addinService.RegisterCmd<BoundBoxDrawCmd>("BoundBoxDraw");
            ribbonControl.Page("程序").Group("模型").ItemLinks
                .NewButton("插入", false, btn => btn.Tag = ("OsgFileImport"), btn => btn.SetImage(Resources.primitives, false))
                .NewButton("删除", false, btn => btn.Tag = ("ModelDelete"), btn => btn.SetImage(Resources.primitives, false))
                .NewButton("高亮", false, btn => btn.Tag = ("HighlightModel"), btn => btn.SetImage(Resources.primitives, false))
                .NewButton("另存为", false, btn => btn.Tag = ("ModelSaveAs"), btn => btn.SetImage(Resources.primitives, false))
                .NewButton("绘制包围框", false, btn => btn.Tag = ("BoundBoxDraw"), btn => btn.SetImage(Resources.primitives, false));

            addinService.RegisterCmd<ViewScreenshotCmd>();
            addinService.RegisterCmd<NodeTreeToXmlFileCmd>();
            ribbonControl.Page("程序").Group("场景").ItemLinks
                .NewButton("取消高亮", false, btn => btn.Tag = ("HighlightCancel"), btn => btn.SetImage(Resources.cancel, false)
                    , btn => btn.Hint = ("取消所有模型的高亮"))
                .NewButton("视图截屏", false, btn => btn.Tag = ("ViewScreenshot"), btn => btn.SetImage(Resources.截图, false)
                    , btn => btn.Hint = ("截取当前程序的视图"))
                .NewButton("输出模型树", false, btn => btn.Tag = ("NodeTreeToXmlFile"), btn => btn.SetImage(Resources.primitives, false));

            addinService.RegisterCmd<SceneSaveAsCmd>();
            addinService.RegisterCmd<OsgFileConvertCmd>();
            addinService.RegisterCmd<BoundBoxInfoCmd>();
            addinService.RegisterCmd<ModelCacheClearCmd>();
            ribbonControl.Page("程序").Group("工具").ItemLinks
                .NewButton("场景另存为", false, btn => btn.Tag = ("SceneSaveAs"), btn => btn.SetImage(Resources.save, false))
                .NewButton("文件转换", false, btn => btn.Tag = ("OsgFileConvert"), btn => btn.SetImage(Resources.loop_alt4_24, false))
                .NewButton("模型大小", false, btn => btn.Tag = ("BoundBoxInfo"), btn => btn.SetImage(Resources.sizes, false))
                .NewButton("清除模型缓存", false, btn => btn.Tag = ("ModelCacheClear"), btn => btn.SetImage(Resources.火箭, true));

            addinService.RegisterCmd<SetViewModeCmd>("SetViewMode");
            ribbonControl.Page("程序").Group("视图").ItemLinks
                .NewButton("显示全图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.ShowAll)), btn => btn.SetImage(Resources.cube, true))
                .NewButton("前视图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.Front)), btn => btn.SetImage(Resources.front_side, false))
                .NewButton("后视图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.Back)), btn => btn.SetImage(Resources.back_side, false))
                .NewButton("左视图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.Left)), btn => btn.SetImage(Resources.left_side, false))
                .NewButton("右视图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.Right)), btn => btn.SetImage(Resources.right_side, false))
                .NewButton("顶视图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.Top)), btn => btn.SetImage(Resources.top_side, false))
                .NewButton("底视图", false, btn => btn.Tag = (new CmdInfo("SetViewMode", ViewMode.Bottom)), btn => btn.SetImage(Resources.bottom_side, false));


            addinService.RegisterCmd<OpenAppConfigPathCmd>("OpenAppConfigPath");
            ribbonControl.Page("程序").Group("配置").ItemLinks
                .NewButton("打开配置路径", false, btn => btn.Tag = ("OpenAppConfigPath"), btn => btn.SetImage(Resources.config, true));

            addinService.RegisterCmd<SlantedImageTestCmd>("SlantedImageTest");
            addinService.RegisterCmd<ChangeManipulatorCmd>("ChangeManipulator");
            addinService.RegisterCmd<AddStateSetManipulatorCmd>("AddStateSetManipulator");
            addinService.RegisterCmd<AddStatsHandlerCmd>("AddStatsHandler");
            addinService.RegisterCmd<TestLineCmd>();
            addinService.RegisterCmd<OpenOsgViewFormCmd>();

            ribbonControl.Pages.Move(0, ribbonControl.Pages.Count - 1);
        }
    }
}
